import 'package:bruno/bruno.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:yt_devops/styles/styles.dart';
import 'package:yt_devops/utils/enums.dart';

class SelfDevEmsControlCommon {
  static Divider divider = Divider(
    color: Colour.dividerColor,
    height: 1.h,
    indent: 16.w,
    endIndent: 16.w,
  );

  static Widget createHeader(item) => Container(
        color: Colour.white,
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: Container(
          height: 53.h,
          alignment: Alignment.centerLeft,
          child: Text(
            item.label,
            style: TextStyle(
              fontWeight: FontWeight.w600,
              fontSize: 18.sp,
            ),
          ),
        ),
      );

  static Widget createRadio(RadioSwitchParams radioParams) => Container(
        color: Colour.white,
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: Container(
          height: 50.h,
          alignment: Alignment.center,
          child: BrnTextSelectFormItem(
            title: radioParams.item.label,
            onTap: radioParams.onTap != null
                ? () => radioParams.onTap!(
                    radioParams.context, radioParams.item, radioParams.index)
                : null,
            value: radioParams.item.value,
            themeData: BrnFormItemConfig(
              titleTextStyle: BrnTextStyle(
                fontSize: 16.sp,
                color: Colour.mainTextColor,
              ),
              hintTextStyle: BrnTextStyle(
                color: Colour.hintTextColor,
                fontSize: 16.sp,
              ),
              contentTextStyle: BrnTextStyle(
                color: radioParams.status == ConnectStatusType.off ||
                        !radioParams.item.enabled
                    ? Colour.hintTextColor
                    : Colour.mainTextColor,
              ),
            ),
          ),
        ),
      );

  static Widget createSwitch(RadioSwitchParams switchParams) => Container(
        color: Colour.white,
        padding: EdgeInsets.symmetric(horizontal: 16.w),
        child: Container(
          height: 50.h,
          alignment: Alignment.center,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                switchParams.item.label,
                style: TextStyle(
                  fontSize: 16.sp,
                  color: Colour.mainTextColor,
                ),
              ),
              CupertinoSwitch(
                value: switchParams.enabled!,
                dragStartBehavior: DragStartBehavior.down,
                activeColor: Colour.primaryColor,
                onChanged: switchParams.onTap != null
                    ? (switchVal) =>
                        switchParams.onTap!(switchParams.context, switchVal)
                    : null,
              ),
            ],
          ),
        ),
      );
}

class RadioSwitchParams {
  /// UI范围
  final BuildContext? context;

  /// 单元数据
  final dynamic item;

  /// 可编辑
  final bool? enabled;

  /// 索引
  final int? index;

  /// 网络连接状态
  final ConnectStatusType? status;

  /// 函数
  final Function? onTap;

  RadioSwitchParams({
    this.context,
    this.item,
    this.enabled,
    this.index,
    this.status,
    this.onTap,
  });
}
